


function ChangeheadBoard()
{
	this.init=function(uid)
	{
		if($('#changeheadboard_'+uid).length>0)
		{
			$('#changeheadboard_'+uid).css('display','block').trigger('click');
			return false;
		}
		_createbox(uid);
		_bind();
	}


	var _createbox=function(uid)
	{
		var html=
		'<div class="changeheadboard owner_'+uid+'" id="changeheadboard_'+uid+'">'+
		'<!--内容页-->'+
		'<div class="changehead_cntboard">'+
		'<!--顶bar-->'+
		'<div class="changehead_bar theme_color_'+uid+'">'+
		'<div class="bar_color theme_color_'+uid+' theme_op_'+uid+'"></div>'+
		'<div class="bar_content">'+
		'<div class="changehead_barname"><img src="img/all_logo16-xp-2014.ico"/>更换头像</div>'+
		'<div class="changehead_imgloadmsg">预览图正在加载中，请稍候...</div>'+
		'<div class="changehead_close" title="关闭"></div>'+
		'<div class="changehead_max normal" title="最大化"></div>'+
		'<div class="changehead_mini" title="最小化"></div>'+
		'<div class="clear"></div>'+
		'</div>'+
		'</div><!--顶bar结束-->'+

		'<!--中部内容-->'+
		'<div class="changehead_middle">'+

		'<!----右侧头像预览栏----->'+
		'<div class="changehead_middle_right">'+
		'<p class="viewtitle">预览:</p>'+
		'<div class="imghead60">'+
		'<div class="imgbackground">'+
		'<img class="hard" src="'+usr.getuser(uid).img+'"/>'+
		'</div>'+
		'</div>'+
		'<div class="imgsize">60×60</div>'+
		'<div class="imghead100">'+
		'<div class="imgbackground">'+
		'<img class="hard" src="'+usr.getuser(uid).img100+'"/>'+
		'<div class="editbar100" type="his">'+
		'<div class="editbar100color"></div>'+
		'<div class="editbar100cnt">'+
		'<img src="img/BigHeadImage/edit.png"/>点击编辑'+
		'</div>'+
		'</div>'+
		'</div>'+
		'</div>'+
		'<div class="imgsize">100×100</div>'+
		'<div class="viewbighead"><img src="img/BigHeadImage/view_hd.png"/><a href="javascript:;" class="link_viewbighead">我的高清头像</a></div>'+
		'<p class="viewtitle">我使用过的头像:</p>'+
		'<div class="imgheadhistorybox">'+
		'<div class="imgheadhistorybox_cnt">'+
		'<div class="imgheadhistorybox_page">'+
		/*
		'<img class="imgheadhistorylist" pid="" src="img/head/69.png"/>'+
		'<img class="imgheadhistorylist" pid="" src="img/head/69.png"/>'+
		'<img class="imgheadhistorylist" pid="" src="img/head/69.png"/>'+
		'<img class="imgheadhistorylist" pid="" src="img/head/69.png"/>'+
		'<img class="imgheadhistorylist" pid="" src="img/head/69.png"/>'+
		'<img class="imgheadhistorylist" pid="" src="img/head/69.png"/>'+
		'<img class="imgheadhistorylist" pid="" src="img/head/69.png"/>'+
		'<img class="imgheadhistorylist" pid="" src="img/head/69.png"/>'+
		'<img class="imgheadhistorylist" pid="" src="img/head/69.png"/>'+
		'<img class="imgheadhistorylist" pid="" src="img/head/69.png"/>'+
		*/
		'</div>'+
		'</div>'+
		'</div>'+

		'</div><!----右侧头像预览栏结束----->'+

		'<!----左侧操作栏 open_(diyboard/classichead/gifhead) 分别打开自定义头像/经典头像/会员头像面板----->'+
		'<div class="changehead_middle_left open_diyboard">'+
		'<!--顶部选择面板bar-->'+
		'<div class="changehead_middle_left_tabbar">'+
		'<div class="changehead_middle_left_tabbtn diyboard">自定义头像</div>'+
		'<div class="changehead_middle_left_tabbtn classichead">经典头像</div>'+
		'<div class="changehead_middle_left_tabbtn gifhead"><img src="img/BigHeadImage/QQvip_16.png"/>动态头像</div>'+
		'</div>'+
		'<!--各面板总内容框 -->'+
		'<div class="changehead_middle_left_tabcontent">'+

		'<!--自定义头像面板-->'+
		'<div class="changehead_diyboard changehead_tabcontent">'+
		'<!--自定义面板照片选择bar-->'+
		'<div class="changehead_diyboard_bar">'+
		'<div class="changehead_diyboard_localphoto"><div class="localphoto_title"><img src="img/BigHeadImage/min_local_pic.png"/>本地照片</div><input type="file" name="input_localphoto" class="input_localphoto"/></div>'+
		'<div class="changehead_diyboard_nowtake"><img src="img/BigHeadImage/video.png"/>自拍头像</div>'+
		'</div>'+
		'<!--自定义面板初始选择面板-->'+
		'<div class="changehead_diyboard_init changehead_diycntboard">'+
		'<div class="changehead_diyboard_init_select">'+
		'<img class="init_select_arrow" src="img/BigHeadImage/CustomSnsHead/arrow.png"/>'+
		'<ul class="init_select_tips">'+
		'<li>您可以选一张本地照片或用摄像头拍照后制作头像。</li>'+
		'<li>本地照片需2M以下,尺寸小于3000*3000</li>'+
		'<li>您也可以点击选择一下其他服务的头像:</li>'+
		'</ul>'+
		'<div class="init_select_content">'+
		'<!--扩展头像编辑服务 hasdata代表有数据--->'+
		'<div class="init_select_tab qqzone hasdata">'+
		'<img class="init_select_tabhead" src="img/BigHeadImage/CustomSnsHead/qzone_default.png"/>'+
		'<div class="init_select_tabtitle"><img src="img/BigHeadImage/CustomSnsHead/qzoneicon_gray.png"/>QQ空间</div>'+
		'<div class="init_select_edithead" title="点击编辑头像"></div>'+
		'</div>'+
		'<div class="init_select_tab friendcricle">'+
		'<img class="init_select_tabhead" src="img/BigHeadImage/CustomSnsHead/friend_default.png"/>'+
		'<div class="init_select_tabtitle"><img src="img/BigHeadImage/CustomSnsHead/friendicon_gray.png"/>朋友网</div>'+
		'<div class="init_select_edithead" title="点击编辑头像"></div>'+
		'</div>'+
		'<div class="init_select_tab qqshow">'+
		'<img class="init_select_tabhead" src="img/BigHeadImage/CustomSnsHead/qqshow_default.png"/>'+
		'<div class="init_select_tabtitle"><img src="img/BigHeadImage/CustomSnsHead/qqshowicon_gray.png"/>QQ秀</div>'+
		'<div class="init_select_edithead" title="点击编辑头像"></div>'+
		'</div>'+
		'</div>'+
		'</div>'+
		'<div class="changehead_diyboard_init_extra">'+
		'<div class="changehead_diyboard_init_extra_titlebar">头像DIY应用</div>'+
		'</div>'+
		'</div>'+
		'<!--自定义面板修改照片面板-->'+
		'<div class="changehead_diyboard_adjust changehead_diycntboard">'+
		'<!--上部修改面板-->'+
		'<div class="changehead_diyboard_adjust_board">'+
		'<div class="changehead_mainpic_box"><!--图片内容盒 根据图片比例大小js调节-->'+
		'<img class="changehead_mainpic" src="img/back2.jpg"/>'+
		'<div class="changehead_mainpic_mask"></div>'+
		'<div class="changehead_adjustable_frame"><!--范围框 必须是正方形-->'+
		'<div class="changehead_adjustable_frame_box"><!--范围框内容盒-->'+
		'<div class="adjustable_frame_backpic" style=""></div>'+
		
		'<div class="adjustable_frame_circle">'+
		'<div class="adjustable_frame_circle_border"></div>'+
		'</div><!--圆形框-->'+

		'<div class="adjustable_frame_net">'+
		'<div class="adjustable_frame_nettr">'+
		'<div class="adjustable_frame_nettd"></div>'+
		'<div class="adjustable_frame_nettd"></div>'+
		'<div class="adjustable_frame_nettd"></div>'+
		'</div>'+
		'<div class="adjustable_frame_nettr">'+
		'<div class="adjustable_frame_nettd"></div>'+
		'<div class="adjustable_frame_nettd"></div>'+
		'<div class="adjustable_frame_nettd"></div>'+
		'</div>'+
		'<div class="adjustable_frame_nettr">'+
		'<div class="adjustable_frame_nettd"></div>'+
		'<div class="adjustable_frame_nettd"></div>'+
		'<div class="adjustable_frame_nettd"></div>'+
		'</div>'+

		'</div><!--网格框-->'+
		
		'</div><!--范围框内容盒结束-->'+

		'<!--范围框边点-->'+
		'<div class="changehead_adjustable_frame_point">'+
		'<div class="frame_point_lefttop"></div>'+
		'<div class="frame_point_righttop"></div>'+
		'<div class="frame_point_leftbottom"></div>'+
		'<div class="frame_point_rightbottom"></div>'+
		'<div class="frame_point_leftmid"></div>'+
		'<div class="frame_point_rightmid"></div>'+
		'<div class="frame_point_topmid"></div>'+
		'<div class="frame_point_bottommid"></div>'+
		'</div><!--范围框边点结束-->'+
		'</div><!--范围框 结束-->'+
		'</div><!--图片内容盒 结束-->'+

		'</div><!--上部修改面板结束-->'+
		'<!--中部工具选择栏-->'+
		'<div class="changehead_diyboard_adjust_toolbar">'+
		'<div class="changehead_diyboard_adjust_tools">'+
		'<div class="adjust_tools_btn filter clicked">滤镜</div>'+
		'<div class="adjust_tools_btn frame">边框</div>'+
		'<div class="adjust_tools_btn gifframe">动态边框</div>'+
		'<div class="adjust_tools_btn tonal">色调</div>'+
		'<div class="adjust_tools_btn virtual">虚化</div>'+
		'</div>'+
		'<div class="adjust_tools_turnleft" title="左转"></div>'+
		'<div class="adjust_tools_turnright" title="右转"></div>'+
		'<div class="adjust_tools_net clicked" title="查看/取消网格线"></div>'+
		'<div class="adjust_tools_circle clicked" title="查看/取消手机头像效果"></div>'+
		'</div><!--中部工具选择栏结束-->'+
		'<!--下部效果预览栏 open_effect_(filter/frame/gifframe/tonal/virtual)表示开启工具栏中选择的页面-->'+
		'<div class="changehead_diyboard_adjust_effect open_effect_filter">'+
		'<!--滤镜栏-->'+
		'<div class="adjust_effect_box effect_filter">'+
		'<!--右侧滚页按钮-->'+
		'<div class="effect_list_page">'+
		'<div class="effect_list_page_back disabled"></div>'+
		'<div class="effect_list_page_ahead"></div>'+
		'</div>'+
		'<!--左侧滚页栏-->'+
		'<div class="effect_list_box">'+
		'<!--滚页条-->'+
		'<div class="effect_list_boxpage">'+
		'<!--单个-->'+
		'<div class="effect_list_one selected">'+
		'<div class="effect_list_pic">'+
		'<div class="effect_pic_box">'+
		'<div class="effect_pic"></div>'+
		'<div class="effect_mask"></div>'+
		'</div>'+

		'</div>'+
		'<p class="typename">原图</p>'+
		'</div>'+
		'<!--单个-->'+
		'<div class="effect_list_one">'+
		'<div class="effect_list_pic">'+
		'<div class="effect_pic_box">'+
		'<div class="effect_pic"></div>'+
		'<div class="effect_mask"><img src="img/danya.png"/></div>'+
		'</div>'+

		'</div>'+
		'<p class="typename">淡雅</p>'+
		'</div>'+
		'</div><!--滚页条结束-->'+
		'</div><!--左侧滚页结束-->'+

		'</div>'+
		'<!--边框栏-->'+
		'<div class="adjust_effect_box effect_frame">'+
		'<!--右侧滚页按钮-->'+
		'<div class="effect_list_page">'+
		'<div class="effect_list_page_back disabled"></div>'+
		'<div class="effect_list_page_ahead"></div>'+
		'</div>'+
		'<!--左侧滚页栏-->'+
		'<div class="effect_list_box">'+
		'<!--滚页条-->'+
		'<div class="effect_list_boxpage">'+
		'<!--单个-->'+
		'<div class="effect_list_one selected">'+
		'<div class="effect_list_pic">'+
		'<div class="effect_pic_box">'+
		'<div class="effect_pic"></div>'+
		'<div class="effect_mask"><img src="img/fugu.png"/></div>'+
		'</div>'+
		'</div>'+
		'<p class="typename">花花边框</p>'+
		'</div>'+
		'</div><!--滚页条结束-->'+
		'</div><!--左侧滚页结束-->'+

		'</div>'+
		'<!--动态边框栏-->'+
		'<div class="adjust_effect_box effect_gifframe">'+
		'<!--右侧滚页按钮-->'+
		'<div class="effect_list_page">'+
		'<div class="effect_list_page_back disabled"></div>'+
		'<div class="effect_list_page_ahead"></div>'+
		'</div>'+
		'<!--左侧滚页栏-->'+
		'<div class="effect_list_box">'+
		'<!--滚页条-->'+
		'<div class="effect_list_boxpage">'+
		'<!--单个-->'+
		'<div class="effect_list_one selected">'+
		'<div class="effect_list_pic">'+
		'<div class="effect_pic_box">'+
		'<div class="effect_pic"></div>'+
		'<div class="effect_mask"><img src="img/fugu.png"/></div>'+
		'</div>'+
		'</div>'+
		'<p class="typename">会动的边框</p>'+
		'</div>'+
		'</div><!--滚页条结束-->'+
		'</div><!--左侧滚页结束-->'+

		'</div>'+
		'<!--色调栏-->'+
		'<div class="adjust_effect_box effect_tonal">'+

		'</div>'+
		'<!--虚化栏-->'+
		'<div class="adjust_effect_box effect_virtual"></div>'+
		'</div><!--下部效果预览栏结束-->'+
		'</div><!--自定义面板修改照片面板结束-->'+

		'</div><!--自定义头像面板结束-->'+

		'<!--经典头像面板-->'+
		'<div class="changehead_classichead changehead_tabcontent">'+
		'<!--经典头像cnt-->'+
		'<div class="changehead_classicheadcnt">'+

		'<!--正在加载page-->'+
		'<div class="changehead_classicheadloadpage">'+
		'<div class="loading"></div>'+
		'<div class="loadfail">'+
		'网络或系统原因加载失败，您可以尝试点击<a class="link_classicreload" href="javascript:;">重新加载</a>'+
		'</div>'+
		'</div>'+

		'<!--经典头像page-->'+
		'<div class="changehead_classicheadcntpage">'+

		'<!--经典头像分类box-->'+
		'<div class="imgbighead_libox">'+
		'<!--分类标题-->'+
		'<div class="imgbighead_libox_title"><img src="img/BigHeadImage/QQvip_16.png"/>会员经典头像<a class="link_moreimghead" href="javascript:;">更多>></a></div>'+
		'<!--分类头像内容-->'+
		'<div class="imgbighead_libocontent">'+

		'<div class="imgbighead_lione">'+
		'<img class="imgbighead_pic" src="img/userhead5_80.jpg" />'+
		'</div>'+

		'</div>'+
		'<div class="clear"></div>'+
		'</div><!--经典头像分类box结束-->'+

		'<!--经典头像分类box-->'+
		'<div class="imgbighead_libox">'+
		'<!--分类标题-->'+
		'<div class="imgbighead_libox_title">推荐头像(个)<a class="link_moreimghead" href="javascript:;">更多>></a></div>'+
		'<!--分类头像内容-->'+
		'<div class="imgbighead_libocontent">'+

		'<div class="imgbighead_lione">'+
		'<img class="imgbighead_pic" src="img/userhead5_80.jpg" />'+
		'</div>'+

		'</div>'+
		'<div class="clear"></div>'+
		'</div><!--经典头像分类box结束-->'+

		'<!--经典头像分类box-->'+
		'<div class="imgbighead_libox">'+
		'<!--分类标题-->'+
		'<div class="imgbighead_libox_title">游戏头像(个)<a class="link_moreimghead" href="javascript:;">更多>></a></div>'+
		'<!--分类头像内容-->'+
		'<div class="imgbighead_libocontent">'+

		'<div class="imgbighead_lione">'+
		'<img class="imgbighead_pic" src="img/userhead5_80.jpg" />'+
		'</div>'+

		'</div>'+
		'<div class="clear"></div>'+
		'</div><!--经典头像分类box结束-->'+

		'</div><!--经典头像page结束-->'+
		'</div><!--经典头像cnt结束-->'+
		'</div><!--经典头像面板结束-->'+

		'<!--动态头像面板-->'+
		'<div class="changehead_gifhead changehead_tabcontent">'+
		'<!--动态头像cnt-->'+
		'<div class="changehead_gifheadcnt">'+

		'<!--正在加载page-->'+
		'<div class="changehead_gifheadloadpage">'+
		'<div class="loading"></div>'+
		'<div class="loadfail">'+
		'网络或系统原因加载失败，您可以尝试点击<a class="link_gifreload" href="javascript:;">重新加载</a>'+
		'</div>'+
		'</div>'+

		'<!--动态头像page-->'+
		'<div class="changehead_gifheadcntpage">'+
		'<!--动态头奖广告推荐板-->'+
		'<div class="gifhead_showboard">'+
		'<img class="gifhead_showboard_img" src="img/BigHeadImage/boardbg.jpg"/>'+
		'<div class="gifhead_showboard_content">'+

		'</div>'+
		'</div>'+

		'<!--头像分类box-->'+
		'<div class="imgbighead_libox">'+
		'<!--分类标题-->'+
		'<div class="imgbighead_libox_title">推荐头像(个)<a class="link_moreimghead" href="javascript:;">更多>></a></div>'+
		'<!--分类头像内容-->'+
		'<div class="imgbighead_libocontent">'+

		'<div class="imgbighead_lione">'+
		'<img class="imgbighead_pic" src="img/userhead5_80.jpg" />'+
		'</div>'+
		'<div class="imgbighead_lione">'+
		'<img class="imgbighead_pic" src="img/userhead5_80.jpg" />'+
		'</div>'+
		'<div class="imgbighead_lione">'+
		'<img class="imgbighead_pic" src="img/userhead5_80.jpg" />'+
		'</div>'+
		'<div class="imgbighead_lione">'+
		'<img class="imgbighead_pic" src="img/userhead5_80.jpg" />'+
		'</div>'+
		'<div class="imgbighead_lione">'+
		'<img class="imgbighead_pic" src="img/userhead5_80.jpg" />'+
		'</div>'+
		'<div class="imgbighead_lione">'+
		'<img class="imgbighead_pic" src="img/userhead5_80.jpg" />'+
		'</div>'+

		'</div>'+
		'<div class="clear"></div>'+
		'</div><!--头像分类box结束-->'+


		'</div><!--动态头像page结束-->'+
		'</div><!--动态头像cnt结束-->'+

		'</div><!--动态头像面板结束-->'+

		'</div><!--各面板总内容框结束-->'+
		'</div><!----左侧操作栏结束----->'+


		'</div><!--中部内容结束-->'+

		'<!--底部按钮bar-->'+
		'<div class="changehead_bottombar theme_color_'+uid+'">'+
		'<div class="changehead_bottombarglass"></div>'+
		'<div class="changehead_bottombarcnt">'+
		'<div class="changehead_bottombutton setting_subcancel">取消</div>'+
		'<!--disabled/highline-->'+
		'<div class="changehead_bottombutton setting_subconfirm highline">确定</div>'+
		'<div class="clear"></div>'+
		'</div>'+
		'</div><!--底部按钮bar结束-->'+

		'</div><!--内容页结束-->'+
		'</div><!---更换头像面板结束--->';

		$('body').append(html);
		//设置顶部bar色
		var th=usr.getpro(uid,'theme');
		$('#changeheadboard_'+uid+' .theme_color_'+uid).css('background',th['bgcolor']);
		$('#changeheadboard_'+uid+' .theme_op_'+uid).css("filter","alpha(opacity="+th['skinopacity']+")").css("-moz-opacity",(th['skinopacity']/100)).css("opacity",(th['skinopacity']/100));

		_ajaxget('needid='+uid+'&&type=gethishead','get_userinfos',function(his)
		{
			//console.log(his);
			var html='';
			html+='<img class="imgheadhistorylist" pid="using" src="'+usr.getuser(uid).img100+'"/>';
			if(his&&his.length>0)
			{
				var harr=his.split(';');
				for(var i=harr.length-1;i>=0;i--)
				{
					if(harr[i].length>0)
					{
						html+='<img class="imgheadhistorylist" pid="'+i+'" src="'+harr[i]+'" title="'+harr[i]+'"/>';
					}
				}
			}
			//console.log(html);
			html+='<div class="clear"></div>';
			$('#changeheadboard_'+uid+' .imgheadhistorybox_page').html(html);
			
			//点击历史头像
			$('.imgheadhistorylist').click(function()
			{
				var uid=$(this).parents('.changeheadboard').attr('id').replace('changeheadboard_','');
				var pid=$(this).attr('pid');
				var src=$(this).attr('src');
				$(this).parents('.changehead_middle_right').find('.imgbackground .hard').attr('src',src).css('display','block');
				$(this).parents('.changehead_middle_right').find('.imgbackground .editbar100').attr('type','his').css('display','block');

				if(pid=='using')
				{
					//tempval.setone(uid,'imghead','his','using');
					tempval.setone(uid,'imghead','src',usr.getuser(uid).img100);
				}
				else
				{	
					//tempval.setone(uid,'imghead','his',true);
					tempval.setone(uid,'imghead','src',src);
				}

				tempval.setone(uid,'imghead','focus','his');
				//tempval.setone(uid,'imghead','scale',1);
				//tempval.setone(uid,'imghead','hisdiy',false);
				/*
				tempval.setone(uid,'imghead','imgw',0);
				tempval.setone(uid,'imghead','imgh',0);
				tempval.setone(uid,'imghead','frameh',0);
				tempval.setone(uid,'imghead','framet',0);
				tempval.setone(uid,'imghead','framel',0);
				*/

				$('#changeheadboard_'+uid+' .imgbackground').css('transform','rotate(0deg)').css('-ms-transform','rotate(0deg)').css('-moz-transform','rotate(0deg)').css('-webkit-transform','rotate(0deg)').css('-o-transform','rotate(0deg)');
				
			});
		});



		//加载系统头像
		loadclassicboard(uid);
		loadgifboard(uid);


	}
	

	function loadclassicboard(uid)
	{
		var cnt=$('#changeheadboard_'+uid+' .changehead_classicheadcnt');
		var page=cnt.find('.changehead_classicheadcntpage');
		page.html('').css('display','none');
		var load=cnt.find('.changehead_classicheadloadpage');
		load.css('display','block');
		load.find('.loadfail').css('display','none');
		load.find('.loading').css('display','block');
		_ajaxget('type=getclassic','get_userheads',function(heads)
		{
			console.log(heads);
			if(heads!='no')
			{
				var html='';
				var vip='',com='',game='';
				var vnum=0,cnum=0,gnum=0;


				for(var i=0;i<heads.length;i++)
				{
					if(parseInt(heads[i]['isvip'])==1)
					{
						vnum+=1;
						vip+='<div class="imgbighead_lione"><img class="imgbighead_pic" headid="'+heads[i].id+'" src="'+heads[i].url+'" /></div>';
					}
					if(parseInt(heads[i]['iscomment'])==1)
					{
						cnum+=1;
						com+='<div class="imgbighead_lione"><img class="imgbighead_pic" headid="'+heads[i].id+'" src="'+heads[i].url+'" /></div>';
					}
					if(parseInt(heads[i]['isgame'])==1)
					{
						gnum+=1;
						game+='<div class="imgbighead_lione"><img class="imgbighead_pic" headid="'+heads[i].id+'" src="'+heads[i].url+'" /></div>';
					}

				}					
				
				vip=
				'<div class="imgbighead_libox viphead">'+
				'<div class="imgbighead_libox_title"><img src="img/BigHeadImage/QQvip_16.png"/>会员经典头像(共'+vnum+'个)<a class="link_moreimghead" href="javascript:;">更多>></a></div>'+
				'<div class="imgbighead_libocontent">'+
				vip+
				'</div><div class="clear"></div></div>';

				com=
				'<div class="imgbighead_libox viphead">'+
				'<div class="imgbighead_libox_title">推荐头像(共'+cnum+'个)<a class="link_moreimghead" href="javascript:;">更多>></a></div>'+
				'<div class="imgbighead_libocontent">'+
				com+
				'</div><div class="clear"></div></div>';

				game=
				'<div class="imgbighead_libox viphead">'+
				'<div class="imgbighead_libox_title">游戏头像(共'+gnum+'个)<a class="link_moreimghead" href="javascript:;">更多>></a></div>'+
				'<div class="imgbighead_libocontent">'+
				game+
				'</div><div class="clear"></div></div>';
								
				html=vip+com+game;
				load.css('display','none');
				page.html(html).css('display','block');

				_bindimg();

				$('.changehead_classichead').mouseover(function()
				{
					Scroll.set($(this),$(this).find('.changehead_classicheadcnt'),$(this).find('.changehead_classicheadcntpage'));
				});
			}
			else
			{
				load.find('.loadfail').css('display','block').html('加载已完成，没有任何数据');
				load.find('.loading').css('display','none');
			}
		},function()
		{
			load.find('.loadfail').css('display','block');
			load.find('.loading').css('display','none');
		});
	}

	function loadgifboard(uid)
	{
		var cnt=$('#changeheadboard_'+uid+' .changehead_gifheadcnt');
		var page=cnt.find('.changehead_gifheadcntpage');
		page.html('').css('display','none');
		var load=cnt.find('.changehead_gifheadloadpage');
		load.css('display','block');
		load.find('.loadfail').css('display','none');
		load.find('.loading').css('display','block');
		_ajaxget('type=getgif','get_userheads',function(heads)
		{
			if(heads!='no')
			{
				var html=
				'<div class="gifhead_showboard">'+
				'<img class="gifhead_showboard_img" src="img/BigHeadImage/boardbg.jpg"/>'+
				'<div class="gifhead_showboard_content">'+
				'</div>'+
				'</div>'+
				''+
				'<div class="imgbighead_libox">'+
				'<!--分类标题-->'+
				'<div class="imgbighead_libox_title">推荐头像(个)<a class="link_moreimghead" href="javascript:;">更多>></a></div>'+
				'<!--分类头像内容-->'+
				'<div class="imgbighead_libocontent">';

				for(var i=0;i<heads.length;i++)
				{
					html+='<div class="imgbighead_lione"><img class="imgbighead_pic" headid="'+heads[i].id+'" src="'+heads[i].url+'" /></div>';
				}	

				
				html+='</div><div class="clear"></div></div>';
				load.css('display','none');
				page.html(html).css('display','block');

				_bindimg();

				$('.changehead_gifhead').mouseover(function()
				{
					Scroll.set($(this),$(this).find('.changehead_gifheadcnt'),$(this).find('.changehead_gifheadcntpage'));
				});
			}
			else
			{
				load.find('.loadfail').css('display','block').html('加载已完成，没有任何数据');
				load.find('.loading').css('display','none');
			}
		},function()
		{
			load.find('.loadfail').css('display','block');
			load.find('.loading').css('display','none');
		});
	}

	var _bindimg=function()
	{
		$('.imgbighead_pic').click(function()
		{
			var uid=$(this).parents('.changeheadboard').attr('id').replace('changeheadboard_','');
			var hid=$(this).attr('headid');
			var url=$(this).attr('src');

			$(this).parents('.changeheadboard').find('.imgbackground .hard').attr('src',url).css('display','block');
			$(this).parents('.changeheadboard').find('.imgbackground .editbar100').attr('type','sys').css('display','block');

			
			tempval.setone(uid,'imghead','focus','sys');
			tempval.setone(uid,'imghead','src',url);
			tempval.setone(uid,'imghead','hid',hid);
			/*
			tempval.setone(uid,'imghead','hisdiy',false);
			tempval.setone(uid,'imghead','imgw',0);
			tempval.setone(uid,'imghead','imgh',0);
			tempval.setone(uid,'imghead','frameh',0);
			tempval.setone(uid,'imghead','framet',0);
			tempval.setone(uid,'imghead','framel',0);
			*/

			$('#changeheadboard_'+uid+' .imgbackground').css('transform','rotate(0deg)').css('-ms-transform','rotate(0deg)').css('-moz-transform','rotate(0deg)').css('-webkit-transform','rotate(0deg)').css('-o-transform','rotate(0deg)');
			

		});
	}




	var _bind=function()
	{
		var bar=$('.changehead_bar');
		drag(bar,bar.parents(".changeheadboard"),'',function(o)
		{
			//console.log(o);
		});
		$('.changehead_close').click(function()
		{
			var uid=$(this).parents('.changeheadboard').attr('id').replace('changeheadboard_','');
			tempval.cleanoneall(uid,'imghead');
			$(this).parents('.changeheadboard').remove();
		});
		$('.changehead_bottombar .setting_subcancel').click(function()
		{
			var uid=$(this).parents('.changeheadboard').attr('id').replace('changeheadboard_','');
			tempval.cleanoneall(uid,'imghead');
			$(this).parents('.changeheadboard').remove();
		});

		$('.changehead_max').click(function(e)
		{
			if($(this).hasClass('normal'))
			{
				//判断当前框的高度
				var cheight=0;
				if (window.innerHeight)
				{
					cheight = window.innerHeight-32;//减去底部的bar
				}
				else if ((document.body) && (document.body.clientHeight))
				{
					cheight = document.body.clientHeight-32;//减去底部的bar
				}
				$(this).parents('.changeheadboard').css('top','0').css('left','0').css('width','100%').css('height',cheight+'px');
				$(this).attr('class','changehead_max big');
			}
			else if($(this).hasClass('big'))
			{
				$(this).parents('.changeheadboard').css('top','2%').css('left','20%').css('width','621px').css('height','466px');
				$(this).attr('class','changehead_max normal');
			}
			e.stopImmediatePropagation();
		});

		//切换面板
		$('.changehead_middle_left_tabbtn').click(function(e)
		{
			if($(this).hasClass('diyboard')&&!$(this).parents('.changehead_middle_left').hasClass('open_diyboard'))
			{
				$(this).parents('.changehead_middle_left').attr('class','changehead_middle_left open_diyboard');
			}
			else if($(this).hasClass('classichead')&&!$(this).parents('.changehead_middle_left').hasClass('open_classichead'))
			{
				$(this).parents('.changehead_middle_left').attr('class','changehead_middle_left open_classichead');
			}
			else if($(this).hasClass('gifhead')&&!$(this).parents('.changehead_middle_left').hasClass('open_gifhead'))
			{
				$(this).parents('.changehead_middle_left').attr('class','changehead_middle_left open_gifhead');
			}
			e.stopImmediatePropagation();
		});

		$('.imgheadhistorybox').mouseover(function()
		{
			Scroll.set($(this),$(this).find('.imgheadhistorybox_cnt'),$(this).find('.imgheadhistorybox_page'));
		});
		
		//重新加载经典头像页链接
		$('.link_classicreload').click(function()
		{
			var uid=$(this).parents('.changeheadboard').attr('id').replace('changeheadboard_','');
			loadclassicboard(uid);
		});
		//重新加载gif头像页链接
		$('.link_gifreload').click(function()
		{
			var uid=$(this).parents('.changeheadboard').attr('id').replace('changeheadboard_','');
			loadgifboard(uid);
		});

		//开启/关闭范围框网格
		$('.adjust_tools_net').click(function(e)
		{
			if($(this).hasClass('clicked'))
			{
				//$(this).parents('.changehead_diyboard_adjust_toolbar').siblings('.changehead_diyboard_adjust_board').find('.adjustable_frame_net').css('display','none');
				$(this).parents('.changehead_diyboard_adjust_toolbar').siblings('.changehead_diyboard_adjust_board').find('.adjustable_frame_net').css("filter","alpha(opacity=0)").css("-moz-opacity",0).css("opacity",0);
				$(this).removeClass('clicked').attr('title','显示网格线');
			}
			else
			{
				//$(this).parents('.changehead_diyboard_adjust_toolbar').siblings('.changehead_diyboard_adjust_board').find('.adjustable_frame_net').css('display','block').css('width','100%').css('height','100%');
				$(this).parents('.changehead_diyboard_adjust_toolbar').siblings('.changehead_diyboard_adjust_board').find('.adjustable_frame_net').css("filter","alpha(opacity=60)").css("-moz-opacity",0.6).css("opacity",0.6);
				$(this).addClass('clicked').attr('title','取消网格线');
			}
			e.stopImmediatePropagation();
		});
		//开启/关闭范围框圆框
		$('.adjust_tools_circle').click(function(e)
		{
			if($(this).hasClass('clicked'))
			{
				$(this).parents('.changehead_diyboard_adjust_toolbar').siblings('.changehead_diyboard_adjust_board').find('.adjustable_frame_circle').css('display','none');
				$(this).removeClass('clicked').attr('title','显示手机头像效果');
			}
			else
			{
				$(this).parents('.changehead_diyboard_adjust_toolbar').siblings('.changehead_diyboard_adjust_board').find('.adjustable_frame_circle').css('display','block');
				$(this).addClass('clicked').attr('title','取消手机头像效果');
			}
			e.stopImmediatePropagation();
		});
		
		//向左旋转
		$('.adjust_tools_turnleft').click(function(e)
		{
			var uid=$(this).parents('.changeheadboard').attr('id').replace('changeheadboard_','');
			//获取图片资源
			var imgbox=$(this).parents('.changeheadboard').find('.changehead_mainpic');
			var imgdata=imgbox.attr('src');

			//翻转图片
			var rotate=tempval.getone(uid,'imghead','rotate');
			rotate==undefined||rotate==null||rotate==false?rotate=-1:rotate-=1;
			(rotate==4||rotate==-4)?rotate=0:'';
			tempval.setone(uid,'imghead','rotate',rotate);
			setoperboard(uid,'url',imgdata,rotate);
			console.log('rotate='+rotate);

			//修改临时数组为初始值

			//临时数组图片翻转标注度数倍数

			e.stopImmediatePropagation();
		});
		//向右旋转
		$('.adjust_tools_turnright').click(function(e)
		{
			var uid=$(this).parents('.changeheadboard').attr('id').replace('changeheadboard_','');
			//获取图片资源
			var imgbox=$(this).parents('.changeheadboard').find('.changehead_mainpic');
			var imgdata=imgbox.attr('src');

			//翻转图片
			var rotate=tempval.getone(uid,'imghead','rotate');
			(rotate==undefined||rotate==null||rotate==false)?rotate=1:rotate+=1;
			(rotate==4||rotate==-4)?rotate=0:'';
			tempval.setone(uid,'imghead','rotate',rotate);
			setoperboard(uid,'url',imgdata,rotate);
			console.log('rotate='+rotate);
			
			e.stopImmediatePropagation();
		});



		//点击编辑使用过/系统自带的头像
		$('.editbar100').click(function(e)
		{
			var uid=$(this).parents('.changeheadboard').attr('id').replace('changeheadboard_','');
			
			//切换回面板
			var tabbtn=$(this).parents('.changeheadboard').find('.changehead_middle_left_tabbtn');
			

			var type=$(this).attr('type');
			var hid=tempval.getone(uid,'imghead','hid');
			var src=tempval.getone(uid,'imghead','src')||$(this).siblings('.hard').attr('src');
			if(type)
			{
				var imghead=tempval.getoneall(uid,'imghead');
				tempval.setone(uid,'imghead','sourceWidth',false);
				tempval.setone(uid,'imghead','sourceHeight',false);
				tempval.setone(uid,'imghead','rotate',false);

				if(type=='his')
				{
					/*
					if((imghead.his!=undefined&&imghead.his=='using')||!imghead)
					{
						setoperboard(uid,'url',usr.getuser(uid).imghd,null,'using');
					}
					else if(imghead.his!=undefined&&imghead.his===true)
					{
						setoperboard(uid,'url',imghead.src,null,true);
					}
					tempval.setone(uid,'imghead','diy',true);
					tempval.setone(uid,'imghead','hisdiy',true);
					tempval.setone(uid,'imghead','sysdiy',false);
					*/
					tabbtn.parents('.changehead_middle_left').attr('class','changehead_middle_left open_diyboard');
					setoperboard(uid,'url',src);
					tempval.setone(uid,'imghead','focus','his');
					tempval.setone(uid,'imghead','editing','his');

				}
				else if(type=='sys')
				{
					//这里先判断是否会员
					_ajaxget('u='+uid+'&&h='+hid+'&&type=vipcheck','get_userheads',function(msg)
					{
						if(msg=='ok')
						{
							tabbtn.parents('.changehead_middle_left').attr('class','changehead_middle_left open_diyboard');
							//setoperboard(uid,'url',tempval.getone(uid,'imghead','src'));
							setoperboard(uid,'url',src);
							/*tempval.setone(uid,'imghead','diy',false);
							tempval.setone(uid,'imghead','hisdiy',false);
							tempval.setone(uid,'imghead','sysdiy',true);
							*/
							tempval.setone(uid,'imghead','focus','sys');
							tempval.setone(uid,'imghead','editing','sys');
							
						}
						else
						{
							//弹出你不是会员提示
						}
					},false,false);
					
				}
			}
			e.stopImmediatePropagation();
		});

		//确定按钮
		$('.changehead_bottombar .setting_subconfirm').click(function(e)
		{
			var uid=$(this).parents('.changeheadboard').attr('id').replace('changeheadboard_','');

			var imghead=tempval.getoneall(uid,'imghead');

			console.log(imghead);

			if(!imghead)
			{
				//关闭本对话框
				$(this).parents('.changeheadboard').remove();
				return false;
			}
			/*
				editing:diy,his,sys (点击编辑头像,自拍，选择本地照片，都需要更改这个参数)
				focus:	diy,his,sys	(点击编辑头像,自拍，选择本地照片，选择diy的图片，选择系统头像，都需要更改这个参数)
				
				editing用于保留diy面板中的参数，提交以focus为准
				如果editing是diy,证明是被编辑过的待上传图片
				如果editing是his或sys,证明是被编辑过的已有图片

				公共:
				frameh: 61
				framel: 4
				framet: 22
				id: 2
				imgh: 100
				imgw: 100
				rotate: -2
				scale: 1
				sourceHeight: 100
				sourceWidth: 100
				src: "img/head/219_100.gif"

				属于sys
				hid: "209"
			
			*/
			var focus=imghead.focus;
			//if(imghead.diy)//如果是diy头像
			if(focus=='diy')
			{
				console.log('提交 diy普通头像');
				//上传文件，使用到FormData创造一个表单来提交图片文件
				var fd=new FormData();
				fd.append('u',uid);
				fd.append('src',imghead.src);
				fd.append('scale',imghead.scale);
				fd.append('imgw',imghead.imgw);
				fd.append('imgh',imghead.imgh);
				fd.append('frameh',imghead.frameh);
				fd.append('framet',imghead.framet);
				fd.append('framel',imghead.framel);
				fd.append('rotate',imghead.rotate==undefined?0:imghead.rotate);
				fd.append('type','diy');

				//h5up(fd,'imgset');
				
				_ajaxupload(fd,'imgset',function(newdata)
				{
					_setdata(uid,newdata);
				});
			}
			if(focus=='his')//如果是历史使用过的头像
			{
				console.log('提交 diy历史头像');
				_ajaxget('u='+uid+'&&src='+imghead.src+'&&type=his'+'&&hisdiy='+(imghead.editing=='his'?1:0)+'&&rotate='+(imghead.rotate==undefined?0:imghead.rotate)+'&&scale='+(imghead.scale==undefined?1:imghead.scale)+'&&imgw='+(imghead.imgw==undefined?0:imghead.imgw)+'&&imgh='+(imghead.imgh==undefined?0:imghead.imgh)+'&&frameh='+(imghead.frameh==undefined?0:imghead.frameh)+'&&framet='+(imghead.framet==undefined?0:imghead.framet)+'&&framel='+(imghead.framel==undefined?0:imghead.framel),'imgset',function(newdata)
				{
					_setdata(uid,newdata);
				});
			}
			else if(focus=='sys')//如果是系统推荐头像
			{
				if(imghead.editing=='sys')//如果系统推荐头像是被编辑过的话
				{
					console.log('提交 编辑过的系统头像');
					_ajaxget('u='+uid+'&&src='+imghead.src+'&&type=sysdiy'+'&&h='+imghead.hid+'&&rotate='+(imghead.rotate==undefined?0:imghead.rotate)+'&&scale='+(imghead.scale==undefined?1:imghead.scale)+'&&imgw='+(imghead.imgw==undefined?0:imghead.imgw)+'&&imgh='+(imghead.imgh==undefined?0:imghead.imgh)+'&&frameh='+(imghead.frameh==undefined?0:imghead.frameh)+'&&framet='+(imghead.framet==undefined?0:imghead.framet)+'&&framel='+(imghead.framel==undefined?0:imghead.framel),'imgset',function(newdata)
					{
						if(newdata!='no')
						{
							_setdata(uid,newdata);
						}
						else
						{

						}
					});
				}
				else
				{
					console.log('提交 原装正版系统头像');
					_ajaxget('u='+uid+'&&h='+imghead.hid+'&&src='+imghead.src+'&&type=sys','imgset',function(newdata)
					{
						if(newdata!='no')
						{
							_setdata(uid,newdata);
						}
						else
						{

						}
					});
				}
			}
			
		});


		//设置头像后调用的公共函数
		var _setdata=function(uid,data)
		{
			console.log(data);
			//将设置好的头像链接更新到全局数组中
			usr.setpro(uid,'imghead_60',data['imghead_60']);
			usr.setpro(uid,'imghead_30',data['imghead_30']);
			usr.setpro(uid,'imghead_100',data['imghead_100']);
			usr.setpro(uid,'imghead_gray',data['imghead_gray']);
			usr.setpro(uid,'imghead_normal',data['imghead_normal']);
			
			//更新大头像到登录框中
			var acclist=Cookie.get('acclist');
			if(acclist)
			{
				//有则替换更新
				eval("var pat=/id_"+uid+"[^\|]+[\|]/m");//------------使用eval来拼接正则表达式------------------------------------------------------
				var onearr=pat.exec(acclist)[0].split(',');
				onearr[3]=data['imghead_100'];
				var newone=onearr.join(',');
				var add=acclist.replace(pat,newone);
				Cookie.set('acclist',add,365);
			}

			//更新界面中所有自己的头像
			$('.owner_'+uid).find('.user_imghead100').attr('src',data['imghead_100']);
			$('.owner_'+uid).find('.user_imghead60').attr('src',data['imghead_60']);
			
			tempval.cleanoneall(uid,'imghead');
			$('#changeheadboard_'+uid).remove();
		}



		//打开摄像头
		$('.changehead_diyboard_nowtake').click(function(e)
		{
			var uid=$(this).parents('.changeheadboard').attr('id').replace('changeheadboard_','');
			if($('#selfcamera_'+uid).length>0)
			{
				$('#selfcamera_'+uid).css('display','block').trigger('click');
				return false;
			}
			$(this).parents('.changeheadboard').append('<div class="changehead_coverboard"></div>');

			$('body').append(
			'<div class="selfcamera owner_'+uid+'" id="selfcamera_'+uid+'">'+
			'<div class="selfcamera_bar">'+
			'自拍头像<div class="selfcamera_close"></div>'+
			'</div>'+
			'<div class="selfcamera_board">'+
			'稍候,正在打开摄像头...'+
			'<div class="selfcamera_photobox"></div>'+
			'<div class="selfcamera_phototaken"><img class="cameraphoto" src="" ></div>'+
			'</div>'+
			'<div class="selfcamera_tools ">'+
			'<div class="takephoto">拍照</div>'+
			'<div class="savephoto">保存</div>'+
			'<div class="retake">重新拍照</div>'+
			'</div>'+
			'</div>	'			
			);

			if($("#photobooth_js").length<=0)
			{
				$('body').append('<script id="photobooth_js" type="text/javascript" src="js/lib/photobooth_min.js"></script>');
			}
			//新建相机对象
			$('#selfcamera_'+uid+' .selfcamera_photobox').photobooth().on("image",function(event,dataUrl)
			{
				//console.log(event);
				//console.log(dataUrl);
				$(this).siblings('.selfcamera_phototaken').find('.cameraphoto').attr('src',dataUrl);
				//$(this).siblings('.selfcamera_phototaken').append('<img class="cameraphoto" src="' + dataUrl + '" >');
				
				$(this).data( "photobooth" ).pause();
				$(this).siblings('.selfcamera_phototaken').css('display','block');
				$(this).css('display','none');
				$(this).parent('.selfcamera_board').siblings('.selfcamera_tools').attr('class','after selfcamera_tools');

			});/*.data("photobooth").resize(300,240);*/
			//$('#selfcamera_'+uid+' .selfcamera_photobox').data( "photobooth" ).forceHSB = true;
			var bar=$('.selfcamera_bar');
			drag(bar,bar.parents(".selfcamera"),'',function(o)
			{
				//console.log(o);
			});
			//关闭自拍框
			$('.selfcamera_close').click(function(e)
			{
				var uid=$(this).parents('.selfcamera').attr('id').replace('selfcamera_','');
				//销毁相机对象
				$('#selfcamera_'+uid+' .selfcamera_photobox').data("photobooth").destroy();
				$('#changeheadboard_'+uid).find('.changehead_coverboard').remove();
				$(this).parents('.selfcamera').remove();
				
				e.stopImmediatePropagation();
			});
			//拍照按钮
			$('.selfcamera_tools .takephoto').click(function(e)
			{
				//var uid=$(this).parents('.selfcamera').attr('id').replace('selfcamera_','');
				//$('#selfcamera_'+uid+' .selfcamera_photobox').trigger('image');
				$(this).parent('.selfcamera_tools').siblings('.selfcamera_board').find('.selfcamera_photobox .trigger').trigger('click');
				e.stopImmediatePropagation();
			});
			//重新拍照
			$('.selfcamera_tools .retake').click(function(e)
			{
				//var uid=$(this).parents('.selfcamera').attr('id').replace('selfcamera_','');
				$(this).parent('.selfcamera_tools').removeClass('after');
				$(this).parent('.selfcamera_tools').siblings('.selfcamera_board').find('.selfcamera_phototaken').css('display','none');
				$(this).parent('.selfcamera_tools').siblings('.selfcamera_board').find('.selfcamera_photobox').css('display','block').data( "photobooth" ).resume();
				e.stopImmediatePropagation();
			});
			
			//保存按钮
			$('.selfcamera_tools .savephoto').click(function(e)
			{
				var uid=$(this).parents('.selfcamera').attr('id').replace('selfcamera_','');

				tempval.setone(uid,'imghead','sourceWidth',false);
				tempval.setone(uid,'imghead','sourceHeight',false);
				tempval.setone(uid,'imghead','rotate',false);
				tempval.setone(uid,'imghead','editing','diy');
				tempval.setone(uid,'imghead','focus','diy');
				//$('#selfcamera_'+uid+' .selfcamera_photobox').trigger('image');
				var dataurl=$(this).parent('.selfcamera_tools').siblings('.selfcamera_board').find('.selfcamera_phototaken .cameraphoto').attr('src');
				
				console.log(dataurl.width);


				//销毁相机对象
				$('#selfcamera_'+uid+' .selfcamera_photobox').data("photobooth").destroy();
				$('#changeheadboard_'+uid).find('.changehead_coverboard').remove();
				$(this).parents('.selfcamera').remove();

				//打开编辑面板，隐藏初始面板
				$('#changeheadboard_'+uid+' .changehead_diyboard_init').css('display','none');
				$('#changeheadboard_'+uid+' .changehead_diyboard_adjust').css('display','block');

				setoperboard(uid,'data',dataurl);

				e.stopImmediatePropagation();
			});

			

			e.stopImmediatePropagation();
		});

		//本地照片
		$('.input_localphoto').change(function(e)
		{
			var ts=e.target;
			var uid=$(this).parents('.changeheadboard').attr('id').replace('changeheadboard_','');
			//var boxpage=$(this).parents('.userintrocard_editintrophoto_boxpage');
		
			tempval.setone(uid,'imghead','sourceWidth',false);
			tempval.setone(uid,'imghead','sourceHeight',false);
			tempval.setone(uid,'imghead','rotate',false);
			tempval.setone(uid,'imghead','editing','diy');
			tempval.setone(uid,'imghead','focus','diy');

			if(ts.files&&ts.files[0])
			{
				//console.log(ts.files[0]);
				//如果不是图片格式，返回并提示
				if(!/image\/\w+/.test(ts.files[0].type))
				{
					console.log("您选择的不是图片噢");
					return false;
				}
				if(ts.files[0].size>1024*1024*2)
				{
					console.log('图片本身过大');
					return false;
				}

				//打开编辑面板，隐藏初始面板
				//$(this).parents('.changehead_diyboard_bar').siblings('.changehead_diyboard_init').css('display','none');
				//$(this).parents('.changehead_diyboard_bar').siblings('.changehead_diyboard_adjust').css('display','block');
				setoperboard(uid,'file',ts.files[0]);
	
			}


			e.stopImmediatePropagation();
		});

	}



	var setoperboard=function(uid,type,imgdata,RotateData)
	{
		RotateData==undefined||RotateData==null||RotateData==''||RotateData==false?RotateData=0:'';
		//打开编辑面板，隐藏初始面板
		$('#changeheadboard_'+uid+' .changehead_diyboard_init').css('display','none');
		$('#changeheadboard_'+uid+' .changehead_diyboard_adjust').css('display','block');

		var board=$('#changeheadboard_'+uid+' .changehead_diyboard_adjust_board');
		var imgbox=board.find('.changehead_mainpic');

		imgbox.attr('src','').css('height','auto').css('width','auto').css('transform-origin','center');
		imgbox.parent('.changehead_mainpic_box').css('height','auto !important').css('width','auto !important').css('margin-top','auto').css('margin-left','auto');//.attr('scale','');

		//1.设置图片
		if(type=="data")
		{
			imgbox.attr('src',imgdata);
			/*if((typeof RotateData=='number'))
			{
				imgbox.css('transform','rotate('+RotateData*90+'deg)').css('-ms-transform','rotate('+RotateData*90+'deg)').css('-moz-transform','rotate('+RotateData*90+'deg)').css('-webkit-transform','rotate('+RotateData*90+'deg)').css('-o-transform','rotate('+RotateData*90+'deg)');
			}
			*/
			setimgboard(uid,board,imgbox,RotateData);
			
		}
		else if(type=="file")
		{
			var fr=new FileReader();
			fr.onload=function(e)
			{
				imgbox.attr('src',e.target.result);

				
				imgloaded(imgbox[0],function(){
					//console.log('加载完成');
					/*if((typeof RotateData=='number'))
					{
						imgbox.css('transform','rotate('+RotateData*90+'deg)').css('-ms-transform','rotate('+RotateData*90+'deg)').css('-moz-transform','rotate('+RotateData*90+'deg)').css('-webkit-transform','rotate('+RotateData*90+'deg)').css('-o-transform','rotate('+RotateData*90+'deg)');
					}
					*/
					setimgboard(uid,board,imgbox,RotateData);
				});
				
			}
			fr.readAsDataURL(imgdata);
		}
		else if(type=="url")
		{
			imgbox.attr('src',imgdata);
			imgbox[0].onload=function()
			{
				//console.log('旋转'+RotateData+','+(typeof RotateData=='number'));
				//console.log('url图片加载完成');
				/*if((typeof RotateData=='number'))
				{
					imgbox.css('transform','rotate('+RotateData*90+'deg)').css('-ms-transform','rotate('+RotateData*90+'deg)').css('-moz-transform','rotate('+RotateData*90+'deg)').css('-webkit-transform','rotate('+RotateData*90+'deg)').css('-o-transform','rotate('+RotateData*90+'deg)');
				}
				*/
				setimgboard(uid,board,imgbox,RotateData);
			}
		}
		
	}
	var setimgboard=function(uid,board,imgbox,RotateData)
	{
		console.log('现在图片宽='+imgbox[0].offsetWidth+' ，高='+imgbox[0].offsetHeight);
		
		/*
		旋转后的图片offsetWidth，offsetHeight均与原来不变，
		所以90度 270度的图片需要特殊处理
		*/


		var imgw=0,imgh=0,s_imgw=0,s_imgh=0,scale=1,transform_origin=false;

		if(tempval.getone(uid,'imghead','sourceWidth'))
		{
			imgw=tempval.getone(uid,'imghead','sourceWidth');
			imgh=tempval.getone(uid,'imghead','sourceHeight');
		}
		else
		{
			imgw=imgbox[0].offsetWidth;
			imgh=imgbox[0].offsetHeight;
			tempval.setone(uid,'imghead','sourceWidth',imgw);
			tempval.setone(uid,'imghead','sourceHeight',imgh);
		}

		if(imgw>3000||imgh>3000)
		{
			console.log('图片尺寸过大！');
			imgbox.attr('src','');
			board.parent('.changehead_diyboard_adjust').siblings('.changehead_diyboard_init').css('display','block');
			board.parent('.changehead_diyboard_adjust').css('display','none');
			return false;
		}
		
		var boardw=board[0].clientWidth;
		var boardh=board[0].clientHeight-2;


		if((typeof RotateData=='number')&&(Math.abs(RotateData)==1||Math.abs(RotateData)==3))
		{
			console.log('转换宽高');
			var temp=imgw;
			imgw=imgh;
			imgh=temp;
			//tempval.setone(uid,'imghead','sourceWidth',imgw);
			//tempval.setone(uid,'imghead','sourceHeight',imgh);

			s_imgh=imgh;
			s_imgw=imgw;

			/*
				如果图片高度大于面板高度,则将图片高度等于面板高度
				如果处理后图片宽度还是溢出，则再将图片宽度等于面板宽度处理
			*/
			if(s_imgh>boardh)
			{
				s_imgh=boardh;
				s_imgw=imgw*boardh/imgh;
			}
			if(s_imgw>boardw)
			{
				s_imgw=boardw;
				s_imgh=boardw*s_imgh/s_imgw;
			}
			//图片缩放比例
			scale=s_imgh/imgh;
			var mt=(boardh-s_imgh)/2;
			
			console.log('imgw='+imgw+' imgh='+imgh+' s_imgh='+s_imgh+' s_imgw='+s_imgw+' mt='+mt+' scale='+scale);
			imgbox.parent('.changehead_mainpic_box').css('height',s_imgh+'px').css('width',s_imgw+'px').css('margin',mt+'px auto');
			imgbox.css('height',s_imgw+'px').css('width',s_imgh+'px');

			if(RotateData==-1||RotateData==3)
			{
				if(Math.max(s_imgw,s_imgh)==s_imgw)
				{
					transform_origin=Math.min(s_imgw,s_imgh)/2;
				}
				else
				{
					transform_origin=Math.max(s_imgw,s_imgh)/2;
				}

			}
			else
			{
				if(Math.max(s_imgw,s_imgh)==s_imgh)
				{
					transform_origin=Math.min(s_imgw,s_imgh)/2;
				}
				else
				{
					transform_origin=Math.max(s_imgw,s_imgh)/2;
				}
			}
			imgbox.css('transform-origin',transform_origin+'px '+transform_origin+'px');
			
		}
		else
		{
			s_imgh=imgh;
			s_imgw=imgw;

			/*
				如果图片高度大于面板高度,则将图片高度等于面板高度
				如果处理后图片宽度还是溢出，则再将图片宽度等于面板宽度处理
			*/
			if(s_imgh>boardh)
			{
				s_imgh=boardh;
				s_imgw=imgw*boardh/imgh;
			}
			if(s_imgw>boardw)
			{
				s_imgw=boardw;
				s_imgh=boardw*s_imgh/s_imgw;
			}
			//图片缩放比例
			scale=s_imgh/imgh;

			var ml=(boardw-s_imgw)/2;
			var mt=(boardh-s_imgh)/2;
			//console.log('mt='+mt+',ml='+ml);
			//console.log('imgw='+imgw+' imgh='+imgh+' s_imgh='+s_imgh+' s_imgw='+s_imgw+' mt='+mt+' scale='+scale);
			imgbox.parent('.changehead_mainpic_box').css('height',s_imgh+'px').css('width',s_imgw+'px').css('margin',mt+'px auto');/*.attr('scale',scale)*///.css('margin-top',mt+'px').css('margin-left',ml+'px');
			imgbox.css('height','100%').css('width','100%');
		}
		imgbox.css('transform','rotate('+RotateData*90+'deg)').css('-ms-transform','rotate('+RotateData*90+'deg)').css('-moz-transform','rotate('+RotateData*90+'deg)').css('-webkit-transform','rotate('+RotateData*90+'deg)').css('-o-transform','rotate('+RotateData*90+'deg)');
		//console.log(imgbox.css('transform-origin'));
		
		//设置范围框位置
		var fh=0;
		if(s_imgh>s_imgw)
		{
			fh=s_imgw*0.8;
		}
		else
		{
			fh=s_imgh*0.8;
		}
		board.find('.changehead_adjustable_frame').css('height',fh+'px').css('width',fh+'px').css('top',(s_imgh-fh)/2+'px').css('left',(s_imgw-fh)/2+'px');
		var backpic=board.find('.changehead_adjustable_frame .adjustable_frame_backpic');
		backpic.css('background','url('+imgbox.attr("src")+')-'+((s_imgw-fh)/2)+'px -'+((s_imgh-fh)/2)+'px no-repeat').css('background-size',s_imgw+'px '+s_imgh+'px');
		if((typeof RotateData=='number'))
		{
			if(Math.abs(RotateData)==1||Math.abs(RotateData)==3)
			{
				backpic.css('background','url('+imgbox.attr("src")+')-'+((s_imgh-fh)/2)+'px -'+((s_imgw-fh)/2)+'px no-repeat').css('background-size',s_imgh+'px '+s_imgw+'px');
			}
			backpic.css('transform','rotate('+RotateData*90+'deg)').css('-ms-transform','rotate('+RotateData*90+'deg)').css('-moz-transform','rotate('+RotateData*90+'deg)').css('-webkit-transform','rotate('+RotateData*90+'deg)').css('-o-transform','rotate('+RotateData*90+'deg)');
		}
		
		
		//设置参数到临时数组中
		//tempval.setone(uid,'imghead','diy',true);
		
		//history!=undefined?tempval.setone(uid,'imghead','focus','his'):'';
		//history!=undefined?tempval.setone(uid,'imghead','editing','his'):'';
		var url=tempval.getone(uid,'imghead','src');
		//tempval.setone(uid,'imghead','src',(history=='using'?usr.getuser(uid).imghd:imgbox.attr("src")));
		tempval.setone(uid,'imghead','src',((url!=undefined||url!=false||url!=null)?url:imgbox.attr("src")));
		tempval.setone(uid,'imghead','scale',scale);
		tempval.setone(uid,'imghead','imgw',s_imgw);
		tempval.setone(uid,'imghead','imgh',s_imgh);
		tempval.setone(uid,'imghead','frameh',fh);
		tempval.setone(uid,'imghead','framet',(s_imgh-fh)/2);
		tempval.setone(uid,'imghead','framel',(s_imgw-fh)/2);
		tempval.setone(uid,'imghead','rotate',RotateData);

		setSelectHeads(uid,RotateData,true);
		_framebind(uid);
	}
	

	//设置被范围框选中范围的各个头像显示
	var setSelectHeads=function(uid,RotateData,isinit)
	{
		$('#changeheadboard_'+uid+' .changehead_imgloadmsg').css('display','block');
		//3种尺寸，40 60 100
		var box=$('#changeheadboard_'+uid+' .changehead_mainpic_box');
		var bh=box[0].offsetHeight;
		var bw=box[0].offsetWidth;
		
		$('#changeheadboard_'+uid+' .imgbackground .hard').css('display','none');
		$('#changeheadboard_'+uid+' .imgbackground .editbar100').css('display','none');

		var effect_pic=$('#changeheadboard_'+uid+' .effect_list_one .effect_pic');
		var img60bg=$('#changeheadboard_'+uid+' .imghead60 .imgbackground');
		var img100bg=$('#changeheadboard_'+uid+' .imghead100 .imgbackground');

		var src=box.find('.changehead_mainpic').attr('src');
		tempval.setone(uid,'imghead','src',src);


		if(!isinit)//如果是正在编辑中
		{
			var imgtmp=tempval.getoneall(uid,'imghead');
			var rotate=imgtmp['rotate'];
			//var imgw=tempval.getone(uid,'imghead','sourceWidth');
			
			var scale=bw/imgtmp['sourceWidth'];
			if(Math.abs(rotate)==1||Math.abs(rotate)==3)
			{
				scale=bh/imgtmp['sourceWidth'];
			}
			scale>1?scale==1:'';
			tempval.setone(uid,'imghead','scale',scale);

			//console.log(imgtmp);
			
			//var src=imgtmp['src'];
			
			var ox=imgtmp['framel'];
			var oy=imgtmp['framet'];
			var fh=imgtmp['frameh'];

			var s4=40/fh,s6=60/fh,s10=100/fh;
			var img4w=s4*bw,img4h=s4*bh;
			var img6w=s6*bw,img6h=s6*bh;
			var img10w=s10*bw,img10h=s10*bh;

			effect_pic.css('background-position','-'+ox*s4+'px -'+oy*s4+'px').css('background-size',img4w+'px '+img4h+'px');
			img60bg.css('background-position','-'+ox*s6+'px -'+oy*s6+'px').css('background-size',img6w+'px '+img6h+'px');
			img100bg.css('background-position','-'+ox*s10+'px -'+oy*s10+'px').css('background-size',img10w+'px '+img10h+'px');

			
			if((typeof rotate=='number'))
			{
				if(Math.abs(rotate)==1||Math.abs(rotate)==3)
				{
					effect_pic.css('background-size',img4h+'px '+img4w+'px');
					img60bg.css('background-size',img6h+'px '+img6w+'px');
					img100bg.css('background-size',img10h+'px '+img10w+'px');
				}
				//effect_pic.css('transform','rotate('+rotate*90+'deg)').css('-ms-transform','rotate('+rotate*90+'deg)').css('-moz-transform','rotate('+rotate*90+'deg)').css('-webkit-transform','rotate('+rotate*90+'deg)').css('-o-transform','rotate('+rotate*90+'deg)');
				$('#changeheadboard_'+uid+' .imgbackground').css('transform','rotate('+rotate*90+'deg)').css('-ms-transform','rotate('+rotate*90+'deg)').css('-moz-transform','rotate('+rotate*90+'deg)').css('-webkit-transform','rotate('+rotate*90+'deg)').css('-o-transform','rotate('+rotate*90+'deg)');
				
			}

		}
		else//如果是初始化diy框时
		{
			console.log('设置头像初始化');

			var frame=box.find('.changehead_adjustable_frame')[0];
			var fh=frame.offsetWidth;
			var ft=frame.offsetTop;
			var fl=frame.offsetLeft;

			var s4=40/fh,s6=60/fh,s10=100/fh;
			var img4w=s4*bw,img4h=s4*bh;
			var img6w=s6*bw,img6h=s6*bh;
			var img10w=s10*bw,img10h=s10*bh;

			effect_pic.css('background','url('+src+')-'+fl*s4+'px -'+ft*s4+'px no-repeat').css('background-size',img4w+'px '+img4h+'px');
			
			img60bg.css('background','url('+src+')-'+fl*s6+'px -'+ft*s6+'px no-repeat').css('background-size',img6w+'px '+img6h+'px');
			
			img100bg.css('background','url('+src+')-'+fl*s10+'px -'+ft*s10+'px no-repeat').css('background-size',img10w+'px '+img10h+'px');
			
			if((typeof RotateData=='number'))
			{
				if(Math.abs(RotateData)==1||Math.abs(RotateData)==3)
				{
					effect_pic.css('background','url('+src+')-'+ft*s4+'px -'+fl*s4+'px no-repeat').css('background-size',img4h+'px '+img4w+'px');
					img60bg.css('background','url('+src+')-'+ft*s6+'px -'+fl*s6+'px no-repeat').css('background-size',img6h+'px '+img6w+'px');
					img100bg.css('background','url('+src+')-'+ft*s10+'px -'+fl*s10+'px no-repeat').css('background-size',img10h+'px '+img10w+'px');
				}

				effect_pic.css('transform','rotate('+RotateData*90+'deg)').css('-ms-transform','rotate('+RotateData*90+'deg)').css('-moz-transform','rotate('+RotateData*90+'deg)').css('-webkit-transform','rotate('+RotateData*90+'deg)').css('-o-transform','rotate('+RotateData*90+'deg)');
				$('#changeheadboard_'+uid+' .imgbackground').css('transform','rotate('+RotateData*90+'deg)').css('-ms-transform','rotate('+RotateData*90+'deg)').css('-moz-transform','rotate('+RotateData*90+'deg)').css('-webkit-transform','rotate('+RotateData*90+'deg)').css('-o-transform','rotate('+RotateData*90+'deg)');
			}

		}		

		$('#changeheadboard_'+uid+' .changehead_imgloadmsg').css('display','none');
		
	}
	


	var _framebind=function(uid)
	{
		/*var box=$('#changeheadboard_'+uid+' .changehead_mainpic_box');
		var frame=box.find('.changehead_adjustable_frame');
		var bh=box[0].offsetWidth;
		var bw=box[0].offsetHeight;
		var fh=frame[0].offsetWidth;

		var mx=bh-fh;
		var my=bw-fh;
		*/
		//范围框拖动
		var frame=$('#changeheadboard_'+uid+' .changehead_adjustable_frame');
		drag(frame,frame,{rangeparent:frame.parents('.changehead_mainpic_box'),downcallback:function(){

			frame.find('.adjustable_frame_circle').css("filter","alpha(opacity=70)").css("-moz-opacity",0.7).css("opacity",0.7);

		},upcallback:function(e)
		{
			if(e!=undefined&&e!=null)
			{
				//console.log($(e.target).attr('class'));
				if($(e.target).attr('class')!=undefined&&$(e.target).parents('.changehead_adjustable_frame')!=undefined&&($(e.target).attr('class').indexOf('changehead_mainpic_mask')>=0||$(e.target).parents('.changehead_adjustable_frame')[0]==frame[0]))
				{
					//console.log('鼠标减压');
					frame.find('.adjustable_frame_circle').css("filter","alpha(opacity=100)").css("-moz-opacity",1).css("opacity",1);
					/*var imgtmp=tempval.getoneall(uid,'imghead');
					
					if(imgtmp['his'])
					{
						if(!imgtmp['hisdiy'])
						{
							tempval.setone(uid,'imghead','his',false);
						}
					}
					*/
					//将正在编辑的类型同步到正在焦点的类型
					tempval.setone(uid,'imghead','focus',tempval.getone(uid,'imghead','editing'));

					setSelectHeads(uid);
					//e.stopImmediatePropagation();
				}
			}
			
		},},function(o)
		{

			var ft=frame[0].offsetTop;
			var fl=frame[0].offsetLeft;
			var fh=frame[0].offsetWidth;

			var ox=fl;
			var oy=ft;

			//console.log('ft='+ft+' fl='+fl);
			
			var backpic=frame.find('.adjustable_frame_backpic');

			var picw=frame.siblings('.changehead_mainpic')[0].offsetWidth;
			var pich=frame.siblings('.changehead_mainpic')[0].offsetHeight;
			
			var rotate=tempval.getone(uid,'imghead','rotate');
			if((typeof rotate=='number')&&rotate!=0)
			{
				if(rotate==-1||rotate==3)
				{
					var y=fl;
					var x=picw-ft-fh;
					ox=x;
					oy=y;
					backpic.css('background-position',-x+'px '+-y+'px');
				}
				else if(rotate==1||rotate==-3)
				{
					var y=pich-fl-fh;
					var x=ft;
					ox=x;
					oy=y;
					backpic.css('background-position',-x+'px '+-y+'px');
				}
				else if(Math.abs(rotate)==2)
				{
					var x=picw-fl-fh;
					var y=pich-ft-fh;
					ox=x;
					oy=y;
					backpic.css('background-position',-x+'px '+-y+'px');
				}
				//console.log('picw='+picw+',pich='+pich+',ft='+ft+',fl='+fl+',x='+x+',y='+y+',ox='+ox+',oy='+oy);
			}
			else
			{
				backpic.css('background-position',-fl+'px '+-ft+'px');
			}
		
			//设置移动位置参数到临时数组中
			//tempval.setone(uid,'imghead','diy',true);
			tempval.setone(uid,'imghead','framet',oy);
			tempval.setone(uid,'imghead','framel',ox);

			o.e.stopImmediatePropagation();
			
		});

		/*
		changehead_mainpic_box
			changehead_adjustable_frame
				<div class="changehead_adjustable_frame_point">
					<div class="frame_point_lefttop"></div>
					<div class="frame_point_righttop"></div>
					<div class="frame_point_leftbottom"></div>
					<div class="frame_point_rightbottom"></div>
					<div class="frame_point_leftmid"></div>
					<div class="frame_point_rightmid"></div>
					<div class="frame_point_topmid"></div>
					<div class="frame_point_bottommid"></div>
				</div><!--范围框边点结束-->
		*/
		var leftmid=frame.find('.frame_point_leftmid');
		drag(leftmid,leftmid,{x:true,posdiy:true,presetcall:function(o){
			console.log(o);
			//var frame=o.mt;
			var fw=frame[0].offsetWidth;
			var fl=frame[0].offsetLeft;
			var ft=frame[0].offsetTop;
			var back=frame.find('.adjustable_frame_backpic');
			
			if(o.left>=-3&&o.left<=0)
			{
				o.left=3;
			}/*else if(o.left<-3)
			{
				o.left-=3;
			}*/
			/*
				停止扩张情况
				1，frame.left<=0
				2, frame.top<=0
				3,frame.top+frame.width>=box.height
				4,frame.left+frame.width>=box.width
				停止缩小情况
				frame.width<=10
			*/
			if((fl+o.left/4)<=0||(ft+o.left/4)<=0||(ft+fw+2)>=frame.parent('.changehead_mainpic_box')[0].offsetHeight||(fl+fw+2)>=frame.parent('.changehead_mainpic_box')[0].offsetWidth||(fw-o.left)<=10)
			{
			}
			else
			{
				frame.css('width',(fw-o.left)+'px').css('height',(fw-o.left)+'px').css('left',(fl+o.left/4)+'px').css('top',(ft+o.left/4)+'px');
				back.css('background-position','-'+(fl+o.left/4)+'px -'+(ft+o.left/4)+'px');	
			}

			var x=fl+o.left/4,y=ft+o.left/4;

			var picw=frame.siblings('.changehead_mainpic')[0].offsetWidth;
			var pich=frame.siblings('.changehead_mainpic')[0].offsetHeight;
			var rotate=tempval.getone(uid,'imghead','rotate');
			if((typeof rotate=='number')&&rotate!=0)
			{
				
				if(rotate==-1||rotate==3)
				{
					y=fl+o.left/4;
					x=picw-(ft+o.left/4)-(fw-o.left);
				}
				else if(rotate==1||rotate==-3)
				{
					y=pich-(fl+o.left/4)-(fw-o.left);
					x=ft+o.left/4;
				}
				else if(Math.abs(rotate)==2)
				{
					x=picw-(fl+o.left/4)-(fw-o.left);
					y=pich-(ft+o.left/4)-(fw-o.left);
				}
				back.css('background-position',-x+'px '+-y+'px');
			}
			
			o.setmove=false;
			//o.left=-3;
			//o.top=o.left+ft;

			//设置移动位置参数到临时数组中
			//tempval.setone(uid,'imghead','diy',true);
			tempval.setone(uid,'imghead','framet',y);
			tempval.setone(uid,'imghead','framel',x);
			tempval.setone(uid,'imghead','frameh',fw-o.left);
			
			return o;
		
		}},function(o)
		{
			o.e.stopImmediatePropagation();
		});

		var rightmid=frame.find('.frame_point_rightmid');
		drag(rightmid,rightmid,{x:true,posdiy:true,presetcall:function(o){
			console.log(o);
			var fw=frame[0].offsetWidth;
			var fl=frame[0].offsetLeft;
			var ft=frame[0].offsetTop;
			var back=frame.find('.adjustable_frame_backpic');
			o.left-=fw;
			/*
				停止扩张情况
				1，frame.left<=0
				2, frame.top<=0
				3,frame.top+frame.width>=box.height
				4,frame.left+frame.width>=box.width
				停止缩小情况
				frame.width<=10
			*/
			if((fl-o.left/4)<=0||(ft-o.left/4)<=0||(ft+fw+2)>=frame.parent('.changehead_mainpic_box')[0].offsetHeight||(fl+fw+2)>=frame.parent('.changehead_mainpic_box')[0].offsetWidth||(fw+o.left)<=10)
			{
			}
			else
			{
				frame.css('width',(fw+o.left)+'px').css('height',(fw+o.left)+'px').css('left',(fl-o.left/4)+'px').css('top',(ft-o.left/4)+'px');
				back.css('background-position','-'+(fl-o.left/4)+'px -'+(ft-o.left/4)+'px');	
			}

			var x=fl-o.left/4,y=ft-o.left/4;

			var picw=frame.siblings('.changehead_mainpic')[0].offsetWidth;
			var pich=frame.siblings('.changehead_mainpic')[0].offsetHeight;
			var rotate=tempval.getone(uid,'imghead','rotate');
			if((typeof rotate=='number')&&rotate!=0)
			{
				
				if(rotate==-1||rotate==3)
				{
					y=fl-o.left/4;
					x=picw-(ft-o.left/4)-fw-o.left;
				}
				else if(rotate==1||rotate==-3)
				{
					y=pich-(fl-o.left/4)-fw-o.left;
					x=ft-o.left/4;
				}
				else if(Math.abs(rotate)==2)
				{
					x=picw-(fl-o.left/4)-fw-o.left;
					y=pich-(ft-o.left/4)-fw-o.left;
				}
				back.css('background-position',-x+'px '+-y+'px');
			}

			
			o.setmove=false;

			//设置移动位置参数到临时数组中
			//tempval.setone(uid,'imghead','diy',true);
			tempval.setone(uid,'imghead','framet',y);
			tempval.setone(uid,'imghead','framel',x);
			tempval.setone(uid,'imghead','frameh',fw+o.left);

			return o;
		
		}},function(o)
		{
			o.e.stopImmediatePropagation();
		});

		var topmid=frame.find('.frame_point_topmid');
		drag(topmid,topmid,{y:true,posdiy:true,presetcall:function(o){
			console.log(o);
			var fw=frame[0].offsetWidth;
			var fl=frame[0].offsetLeft;
			var ft=frame[0].offsetTop;
			var back=frame.find('.adjustable_frame_backpic');
			if(o.top>=-3&&o.top<=0)
			{
				o.top=3;
			}
			/*
				停止扩张情况
				1，frame.left<=0
				2, frame.top<=0
				3,frame.top+frame.width>=box.height
				4,frame.left+frame.width>=box.width
				停止缩小情况
				frame.width<=10
			*/
			if((fl+o.top/4)<=0||(ft+o.top/4)<=0||(ft+fw+2)>=frame.parent('.changehead_mainpic_box')[0].offsetHeight||(fl+fw+2)>=frame.parent('.changehead_mainpic_box')[0].offsetWidth||(fw-o.top)<=10)
			{
			}
			else
			{
				frame.css('width',(fw-o.top)+'px').css('height',(fw-o.top)+'px').css('left',(fl+o.top/4)+'px').css('top',(ft+o.top/4)+'px');
				back.css('background-position','-'+(fl+o.top/4)+'px -'+(ft+o.top/4)+'px');	
			}
			
			var x=fl+o.top/4,y=ft+o.top/4;

			var picw=frame.siblings('.changehead_mainpic')[0].offsetWidth;
			var pich=frame.siblings('.changehead_mainpic')[0].offsetHeight;
			var rotate=tempval.getone(uid,'imghead','rotate');
			if((typeof rotate=='number')&&rotate!=0)
			{
				
				if(rotate==-1||rotate==3)
				{
					y=fl+o.top/4;
					x=picw-(ft+o.top/4)-(fw-o.top);
				}
				else if(rotate==1||rotate==-3)
				{
					y=pich-(fl+o.top/4)-(fw-o.top);
					x=ft+o.top/4;
				}
				else if(Math.abs(rotate)==2)
				{
					x=picw-(fl+o.top/4)-(fw-o.top);
					y=pich-(ft+o.top/4)-(fw-o.top);
				}
				back.css('background-position',-x+'px '+-y+'px');
			}

			o.setmove=false;
			
			//设置移动位置参数到临时数组中
			//tempval.setone(uid,'imghead','diy',true);
			tempval.setone(uid,'imghead','framet',y);
			tempval.setone(uid,'imghead','framel',x);
			tempval.setone(uid,'imghead','frameh',fw-o.top);

			return o;
		
		}},function(o)
		{
			o.e.stopImmediatePropagation();
		});

		var bottommid=frame.find('.frame_point_bottommid');
		drag(bottommid,bottommid,{y:true,posdiy:true,presetcall:function(o){
			console.log(o);
			var fw=frame[0].offsetWidth;
			var fl=frame[0].offsetLeft;
			var ft=frame[0].offsetTop;
			var back=frame.find('.adjustable_frame_backpic');
			o.top-=fw;
			/*
				停止扩张情况
				1，frame.left<=0
				2, frame.bottom<=0
				3,frame.bottom+frame.width>=box.height
				4,frame.left+frame.width>=box.width
				停止缩小情况
				frame.width<=10
			*/
			if((fl-o.top/4)<=0||(ft-o.top/4)<=0||(ft+fw+2)>=frame.parent('.changehead_mainpic_box')[0].offsetHeight||(fl+fw+2)>=frame.parent('.changehead_mainpic_box')[0].offsetWidth||(fw+o.top)<=10)
			{
			}
			else
			{
				frame.css('width',(fw+o.top)+'px').css('height',(fw+o.top)+'px').css('left',(fl-o.top/4)+'px').css('top',(ft-o.top/4)+'px');
				back.css('background-position','-'+(fl-o.top/4)+'px -'+(ft-o.top/4)+'px');	
			}
			
			var x=fl-o.top/4,y=ft-o.top/4;

			var picw=frame.siblings('.changehead_mainpic')[0].offsetWidth;
			var pich=frame.siblings('.changehead_mainpic')[0].offsetHeight;
			var rotate=tempval.getone(uid,'imghead','rotate');
			if((typeof rotate=='number')&&rotate!=0)
			{
				
				if(rotate==-1||rotate==3)
				{
					y=fl-o.top/4;
					x=picw-(ft-o.top/4)-fw-o.top;
				}
				else if(rotate==1||rotate==-3)
				{
					y=pich-(fl-o.top/4)-fw-o.top;
					x=ft-o.top/4;
				}
				else if(Math.abs(rotate)==2)
				{
					x=picw-(fl-o.top/4)-fw-o.top;
					y=pich-(ft-o.top/4)-fw-o.top;
				}
				back.css('background-position',-x+'px '+-y+'px');
			}

			o.setmove=false;

			//设置移动位置参数到临时数组中
			//tempval.setone(uid,'imghead','diy',true);
			tempval.setone(uid,'imghead','framet',y);
			tempval.setone(uid,'imghead','framel',x);
			tempval.setone(uid,'imghead','frameh',fw+o.top);
			
			return o;
		
		}},function(o)
		{
			o.e.stopImmediatePropagation();
		});



		//---------------------------------------------

		//左上 新情况不好
		var lefttop=frame.find('.frame_point_lefttop');
		drag(lefttop,lefttop,{posdiy:true,presetcall:function(o){
			//console.log(o);
			//var frame=o.mt;
			var fw=frame[0].offsetWidth;
			var fl=frame[0].offsetLeft;
			var ft=frame[0].offsetTop;
			var back=frame.find('.adjustable_frame_backpic');

			/*
				停止扩张情况
				1，frame.left<=0
				2, frame.top<=0
				3,frame.top+frame.width>=box.height
				4,frame.left+frame.width>=box.width
				停止缩小情况
				frame.width<=10
			*/
			
			if(o.left>=-3&&o.left<=0)
			{
				o.left=3;
			}
			if(o.top>=-3&&o.top<=0)
			{
				o.top=3;
			}
			
			if((fl+o.left/4)<=0||(ft+o.top/4)<=0||(ft+fw+2)>=frame.parent('.changehead_mainpic_box')[0].offsetHeight||(fl+fw+2)>=frame.parent('.changehead_mainpic_box')[0].offsetWidth||(fw-o.left)<=10)
			{
			}
			else
			{
				frame.css('width',(fw-o.left)+'px').css('height',(fw-o.left)+'px').css('left',(fl+o.left/4)+'px').css('top',(ft+o.top/4)+'px');
				back.css('background-position','-'+(fl+o.left/4)+'px -'+(ft+o.top/4)+'px');	
			}
			
			/*
			var l_abs=Math.abs(o.left);
			var t_abs=Math.abs(o.top);
			
			var max=Math.max(l_abs,t_abs);
			var d=max;

			if(o.left>=0&&o.top>=0)
			{
				d=-d;
			}
			console.log((ft+fw+d)<frame.parent('.changehead_mainpic_box')[0].offsetHeight);
			if((fl-d)>0&&(ft-d)>0&&(ft+fw+d)<frame.parent('.changehead_mainpic_box')[0].offsetHeight&&(fl+fw+d)<frame.parent('.changehead_mainpic_box')[0].offsetWidth&&(fw+d)>10)
			{
				frame.css('width',(fw+d)+'px').css('height',(fw+d)+'px').css('left',(fl-d)+'px').css('top',(ft-d)+'px');
				back.css('background-position','-'+(fl-d)+'px -'+(ft-d)+'px');	
			}
			*/
			var x=fl+o.left/4,y=ft+o.top/4;

			var picw=frame.siblings('.changehead_mainpic')[0].offsetWidth;
			var pich=frame.siblings('.changehead_mainpic')[0].offsetHeight;
			var rotate=tempval.getone(uid,'imghead','rotate');
			if((typeof rotate=='number')&&rotate!=0)
			{
				
				if(rotate==-1||rotate==3)
				{
					y=fl+o.left/4;
					x=picw-(ft+o.top/4)-(fw-o.left);
				}
				else if(rotate==1||rotate==-3)
				{
					y=pich-(fl+o.left/4)-(fw-o.left);
					x=ft+o.top/4;
				}
				else if(Math.abs(rotate)==2)
				{
					x=picw-(fl+o.left/4)-(fw-o.left);
					y=pich-(ft+o.top/4)-(fw-o.left);
				}
				back.css('background-position',-x+'px '+-y+'px');
			}
			
			o.setmove=false;

			//设置移动位置参数到临时数组中
			//tempval.setone(uid,'imghead','diy',true);
			tempval.setone(uid,'imghead','framet',y);
			tempval.setone(uid,'imghead','framel',x);
			tempval.setone(uid,'imghead','frameh',fw-o.left);

			return o;
		
		}},function(o)
		{
			o.e.stopImmediatePropagation();
		});


		//左下 完成还好
		var leftbottom=frame.find('.frame_point_leftbottom');
		drag(leftbottom,leftbottom,{posdiy:true,presetcall:function(o){
			console.log(o);
			//var frame=o.mt;
			var fw=frame[0].offsetWidth;
			var fl=frame[0].offsetLeft;
			var ft=frame[0].offsetTop;
			var back=frame.find('.adjustable_frame_backpic');
			o.top-=fw;
			/*if(o.left>=-3&&o.left<=0)
			{
				o.left=3;
			}
			*/
			var l_abs=Math.abs(o.left);
			var t_abs=Math.abs(o.top);
			
			var max=Math.max(l_abs,t_abs);
			var d=max;
			if(o.left>0)
			{
				d=-d;
			}
			
			/*
				停止扩张情况
				1，frame.left<=0
				
				2,frame.top+frame.width>=box.height
				3,frame.left+frame.width>=box.width
				停止缩小情况
				1,frame.width<=10
			*/
			if((fl-d)>0&&(ft+fw+d)<frame.parent('.changehead_mainpic_box')[0].offsetHeight&&(fl+fw+d)<frame.parent('.changehead_mainpic_box')[0].offsetWidth&&(fw+d)>10)
			{
				frame.css('width',(fw+d)+'px').css('height',(fw+d)+'px').css('left',(fl-d)+'px');
				back.css('background-position','-'+(fl-d)+'px -'+ft+'px');	
			}

			var x=fl-d,y=ft;

			var picw=frame.siblings('.changehead_mainpic')[0].offsetWidth;
			var pich=frame.siblings('.changehead_mainpic')[0].offsetHeight;
			var rotate=tempval.getone(uid,'imghead','rotate');
			if((typeof rotate=='number')&&rotate!=0)
			{
				
				if(rotate==-1||rotate==3)
				{
					y=fl-d;
					x=picw-ft-fw-d;
				}
				else if(rotate==1||rotate==-3)
				{
					y=pich-(fl-d)-fw-d;
					x=ft;
				}
				else if(Math.abs(rotate)==2)
				{
					x=picw-(fl-d)-fw-d;
					y=pich-ft-fw-d;
				}
				back.css('background-position',-x+'px '+-y+'px');
			}
			
			o.setmove=false;
			
			//设置移动位置参数到临时数组中
			//tempval.setone(uid,'imghead','diy',true);
			tempval.setone(uid,'imghead','framet',y);
			tempval.setone(uid,'imghead','framel',x);
			tempval.setone(uid,'imghead','frameh',fw+d);

			return o;
		
		}},function(o)
		{
			o.e.stopImmediatePropagation();
		});


		//右上 勉强完成
		var righttop=frame.find('.frame_point_righttop');
		drag(righttop,righttop,{posdiy:true,presetcall:function(o){
			console.log(o);
			//var frame=o.mt;
			var fw=frame[0].offsetWidth;
			var fl=frame[0].offsetLeft;
			var ft=frame[0].offsetTop;
			var back=frame.find('.adjustable_frame_backpic');
			o.left-=fw;
			/*if(o.top>=-3&&o.top<=0)
			{
				o.top=3;
			}*/
			
			var l_abs=Math.abs(o.left);
			var t_abs=Math.abs(o.top);
			//var delta=Math.sqrt((l_abs*l_abs+t_abs*t_abs)/2);

			var max=Math.max(l_abs,t_abs);
			/*
				停止扩张情况
				1, frame.top<=0
				2,frame.top+frame.width>=box.height
				3,frame.left+frame.width>=box.width
				停止缩小情况
				1,frame.width<=10
			*/
			var d=max;				
			if(o.left<o.top)
			{
				d=-d;
			}
			if((ft-d/2)>0&&(ft+fw+d)<frame.parent('.changehead_mainpic_box')[0].offsetHeight&&(fl+fw+d)<frame.parent('.changehead_mainpic_box')[0].offsetWidth&&(fw+d)>10)
			{
				frame.css('width',(fw+d)+'px').css('height',(fw+d)+'px').css('top',(ft-d/2)+'px');
				back.css('background-position','-'+fl+'px -'+(ft-d/2)+'px');	
			}

			var x=fl,y=ft-d/2;

			var picw=frame.siblings('.changehead_mainpic')[0].offsetWidth;
			var pich=frame.siblings('.changehead_mainpic')[0].offsetHeight;
			var rotate=tempval.getone(uid,'imghead','rotate');
			if((typeof rotate=='number')&&rotate!=0)
			{
				if(rotate==-1||rotate==3)
				{
					y=fl;
					x=picw-(ft-d/2)-fw-d;
				}
				else if(rotate==1||rotate==-3)
				{
					y=pich-fl-fw-d;
					x=ft-d/2;
				}
				else if(Math.abs(rotate)==2)
				{
					x=picw-fl-fw-d;
					y=pich-(ft-d/2)-fw-d;
				}
				back.css('background-position',-x+'px '+-y+'px');
			}

			
			o.setmove=false;
			
			//设置移动位置参数到临时数组中
			//tempval.setone(uid,'imghead','diy',true);
			tempval.setone(uid,'imghead','framet',y);
			tempval.setone(uid,'imghead','framel',x);
			tempval.setone(uid,'imghead','frameh',fw+d);

			return o;
		
		}},function(o)
		{
			o.e.stopImmediatePropagation();
		});
	

		//右下 完成
		var rightbottom=frame.find('.frame_point_rightbottom');
		drag(rightbottom,rightbottom,{posdiy:true,presetcall:function(o){

			var fw=frame[0].offsetWidth;
			var fl=frame[0].offsetLeft;
			var ft=frame[0].offsetTop;
			var back=frame.find('.adjustable_frame_backpic');
			o.left-=fw;
			o.top-=fw;
			
			var l_abs=Math.abs(o.left);
			var t_abs=Math.abs(o.top);
			
			var max=Math.max(l_abs,t_abs);
			var d=max;
			if(o.left<0)
			{
				d=-d;
			}
			/*
				停止扩张情况
				1,frame.top+frame.width>=box.height
				2,frame.left+frame.width>=box.width
				停止缩小情况
				1,frame.width<=10
			*/
			
			


			if((ft+fw+d)<frame.parent('.changehead_mainpic_box')[0].offsetHeight&&(fl+fw+d)<frame.parent('.changehead_mainpic_box')[0].offsetWidth&&(fw+d)>10)
			{
				frame.css('width',(fw+d)+'px').css('height',(fw+d)+'px');
			}

			var x=fl,y=ft;

			var picw=frame.siblings('.changehead_mainpic')[0].offsetWidth;
			var pich=frame.siblings('.changehead_mainpic')[0].offsetHeight;
			var rotate=tempval.getone(uid,'imghead','rotate');
			if((typeof rotate=='number')&&rotate!=0)
			{
				
				if(rotate==-1||rotate==3)
				{
					y=fl;
					x=picw-ft-fw-d;
				}
				else if(rotate==1||rotate==-3)
				{
					y=pich-fl-fw-d;
					x=ft;
				}
				else if(Math.abs(rotate)==2)
				{
					x=picw-fl-fw-d;
					y=pich-ft-fw-d;
				}
				back.css('background-position',-x+'px '+-y+'px');
			}
			

			o.setmove=false;

			//设置移动位置参数到临时数组中
			//tempval.setone(uid,'imghead','diy',true);
			tempval.setone(uid,'imghead','framet',y);
			tempval.setone(uid,'imghead','framel',x);
			tempval.setone(uid,'imghead','frameh',fw+d);
			
			return o;
		
		}},function(o)
		{
			o.e.stopImmediatePropagation();
		});

	}





	

}